package com.poi.qianmi.fetch.demo3;

import com.monitorjbl.xlsx.StreamingReader;
import com.poi.qianmi.jol.JolDetection;
import com.poi.qianmi.model.User;
import com.poi.qianmi.path.GlobalPath;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname Fetch3Application
 * @Description TODO
 * @Date 2019/9/19 8:42 下午
 * @Created by xiaocai
 */

public class Fetch3Mmain {

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        InputStream is;
        try {
            is = new FileInputStream(new File(GlobalPath.getInstance(90)));
            Workbook workbook = StreamingReader.builder()
                    .rowCacheSize(100)    // number of rows to keep in memory (defaults to 10)
                    .bufferSize(4096)     // buffer size to use when reading InputStream to file (defaults to 1024)
                    .open(is);            // InputStream or File for XLSX file (required)

            List<User> userList = new ArrayList();
            for (Sheet sheet : workbook) {
                for (Row r : sheet) {
                    User user = User.builder().build();
                    for (Cell c : r) {
                        if (c.getColumnIndex() == 0) {
                            user.setName(c.getStringCellValue());
                        } else if (c.getColumnIndex() == 1) {
                            user.setAdress(c.getStringCellValue());
                        } else if (c.getColumnIndex() == 2) {
                            user.setVip(c.getStringCellValue());
                        } else if (c.getColumnIndex() == 3) {
                            user.setRemark(c.getStringCellValue());
                        }
                    }
                    userList.add(user);
                }
            }
            JolDetection.detection(userList);
            long endTime = System.currentTimeMillis();
            System.out.println("处理数据条数：" + userList.size() + " 条");
            System.out.println("程序运行时间： " + (endTime - startTime) + "ms");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
